//#include<iostream>
//#include<vector>
//using namespace std;
//
//int main()
//{
//	int ar[] = { 1,2,3,4,0,5,6,7,8,9 };
//	int n = sizeof(ar) / sizeof(int);
//	vector<int> v(ar, ar + n);
//	vector<int>::iterator it = v.begin();
//	while (it != v.end())
//	{
//		if (*it != 0)
//			cout << *it;
//		else
//			v.erase(it);
//		it++;
//	}
//	return 0;
//}

//#include<iostream>
//#include<vector>
//using namespace std;
//
//class Solution 
//{
//public:
//    vector<string> letterCombinations(string digits) 
//    {
//        string b = { "   abcdefghijklmnopqrstuvwxyz" };
//    }
//};
//
//
//int main()
//{
//    return 0;
//}


#include<iostream>
#include<vector>
using namespace std;

class Solution
{
public:
    vector<string> letterCombinations(string digits)
    {
        static const char zm[] = "      abcdefghijklmnopqrstuvwxyz";
        int n = digits.size();
        int z = 1;
        for (int i = 0; i < n; i++)
            z *= 3;
        vector<string> v;
        v.resize(z);
        int z2 = z;

        for (int i = 0; i < n; i++)
        {
            int u = 0;
            int di = digits[i] - '0';
        begin:

            int y = u;
            for (int t = 0 + y; t < z / 3 + y; t++)
            {
                v[t].push_back(zm[di * 3]);
                u++;
            }
            for (int t = z / 3 + y; t < (z / 3) * 2 + y; t++)
            {
                v[t].push_back(zm[di * 3 + 1]);
                u++;
            }

            for (int r = (z / 3) * 2 + y; r < z + y; r++)
            {
                v[r].push_back(zm[di * 3 + 2]);
                u++;
            }
            if (u < z2)
                goto begin;
            z /= 3;
        }
        return v;
    }
};


int main()
{
    string a = "23";
    Solution b;
    vector<string> c = b.letterCombinations(a);
    for (auto it : c)
    {
        for (auto is : it)
        {
            cout << is << ' ';
        }
        cout << endl;
    }
    return 0;
}